package com.boc.langxiang.presenter.me;

import com.boc.langxiang.contract.me.AccountSetContract;
import com.boc.langxiang.entity.request.AccountUpdateInfoRequest;
import com.boc.langxiang.entity.response.AccountUpdateInfoContent;
import com.boc.langxiang.entity.response.BaseResponse;
import com.boc.langxiang.net.ApiService;
import com.boc.langxiang.net.HandleErrorSubscriber;
import com.boc.langxiang.net.NetClient;

import rx.Observable;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

public class AccountSetPresenter implements AccountSetContract.Presenter {

    private  ApiService mService;
    private AccountSetContract.View mView;

    public AccountSetPresenter(AccountSetContract.View view){
        mService = NetClient.getInstance().net().create(ApiService.class);
        this.mView = view;
    }

    @Override
    public void accountUpdateInfo() {
        mView.showLoading();
        AccountUpdateInfoRequest request = new AccountUpdateInfoRequest();
        Observable<BaseResponse<AccountUpdateInfoContent>> accountUpdateInfo = mService.accountUpdateInfo(request.params());
        accountUpdateInfo.subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .unsubscribeOn(Schedulers.io())
                .subscribe(new HandleErrorSubscriber<BaseResponse<AccountUpdateInfoContent>>(mView) {
                    @Override
                    public void onSuccess(BaseResponse<AccountUpdateInfoContent> response) {
                        AccountUpdateInfoContent content = response.getContent();
                        mView.getAccountUpdateInfoContent(content);
                    }
                });
    }
}
